package cn.stylefeng.guns.modular.basic.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.basic.entity.BasicLine;
import cn.stylefeng.guns.modular.basic.mapper.BasicLineMapper;
import cn.stylefeng.guns.modular.basic.model.params.BasicLineParam;
import cn.stylefeng.guns.modular.basic.model.result.BasicLineIneResult;
import cn.stylefeng.guns.modular.basic.model.result.BasicLineResult;
import  cn.stylefeng.guns.modular.basic.service.BasicLineService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 项目线路表 服务实现类
 */
@Service
public class BasicLineServiceImpl extends ServiceImpl<BasicLineMapper, BasicLine> implements BasicLineService {

    @Override
    public void add(BasicLineParam param){
        BasicLine entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BasicLineParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BasicLineParam param){
        BasicLine oldEntity = getOldEntity(param);
        BasicLine newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BasicLineResult findBySpec(BasicLineParam param,Long operateId){
        return this.baseMapper.findBySpec(param,operateId);
    }

    @Override
    public List<BasicLineResult> findListBySpec(BasicLineParam param,Long operateId){
        return this.baseMapper.findListBySpec(param, operateId);
    }

    @Override
    public List<BasicLineResult> listByOperateId(Long operateId){
        return this.baseMapper.listByOperateId(operateId);
    }


    @Override
    public LayuiPageInfo findPageBySpec(BasicLineParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(BasicLineParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BasicLine getOldEntity(BasicLineParam param) {
        return this.getById(getKey(param));
    }

    private BasicLine getEntity(BasicLineParam param) {
        BasicLine entity = new BasicLine();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public List<BasicLineResult> sumfindListBySpec(BasicLineParam param) {
		return this.baseMapper.sumfindListBySpec(param);
	}

    @Override
    public BasicLineResult findByName(String name, Long operateId) {
        return this.baseMapper.findByName(name,operateId);
    }

}
